import { method } from 'lodash'
import request from './request'

export function loginApi(data){
    return request({
        url:'/login',
        method:'POST',
        data:data
    })
}

// 获取权限菜单的借口
export function menusApi(){
    return request({
        url:'/menus',
        method:'GET',
    })
}


//数据渲染
export function userlistApi(params){
    return request({
        url:'/users',
        method:'GET',
        params
    })
}

//添加接口
export function addone(data){
    return request({
        url:'/users',
        method:'POST',
        data
    })
}

//添加接口
export function shujuAPI(){
    return request({
        url:'/reports/type/1',
        method:'GET',
        
    })
}




//删除
export function delone(data){
    return request({
        url:'/users/'+data,
        method:'delete',
        data
    })
}

//修改
export function bjone(id,data){
    return request({
        url:`/users/${id}`,
        method:'put',
        data
    })
}

// 改变用户状态
export function setone(uid,type){
    return request({
        url:`/users/${uid}/state/${type}`,
        method:'put',
    })
}

// 分配角色
export function roles(){
    return request({
        url:'/roles',
        method:'get',
    })
}
export function rolefeng(id,rid){
    return request({
        url:`users/${id}/role`,
        method:'put',
        data:{rid}
    })
}

// 获取权限列表
export function rightlist(type='list'){
    return request({
        url:`rights/${type}`,
        method:'get'
    })
}

// 获取角色列表
export function rolelist(){
    return request({
        url:'/roles',
        method:'get',
    })
}
// 添加角色
export function addrolelist(data){
    return request({
        url:'/roles',
        method:'post',
        data
    })
}
// 编辑角色列表
export function rolebian(data){
    return request({
        url:`/roles/${data.id}`,
        method:'put',
        data:{
            roleName:data.roleName,
            roleDesc:data.roleDesc
        }
    })

}

// 删除角色列表
export function delrole(id){
    return request({
        url:`/roles/${id}`,
        method:'delete',
    })
}

export function delrightapi(roleId,rightId){
    return request({
        url: `/roles/${roleId}/rights/${rightId}`,
        method:'delete'
    })
}

// 
export function treelist(type='tree'){
    return request({
        url:`rights/${type}`,
        method:'get'
    })
}
//角色分配权限
export function getCheckedApi(roleId,rids){
    return request({
        url:`/roles/${roleId}/rights`,
        method:'POST',
        data:{rids}
    })
}

export function goodslistapi(params){
    return request({
        url:'/goods',
        method:'get',
        params
    })
}

export function goodsdellist(id){
    return request({
        url:`/goods/${id}`,
        method:'delete'
    })
}

export function goodscatelist(type=3){
    return request({
        url:'/categories',
        method:'get',
        params:{
            type
        }
    })
}
export function goodsfenl(id,sel="many"){
    return request({
        url:`/categories/${id}/attributes`,
        method:'get',
        params:{sel}
    })
}
export function addgoods(data){
    return request({
        url:'goods',
        method:'POST',
        data
    })
}